import { request } from "../request";

// 返回数据接口
export interface GetResourcesListRes {
  code: number;
  message: string;
  data: {
    resourceId: number;
    chatId: number;
    userId: number;
    ossUrl: string;
    type: string;
    createdAt: Record<string, unknown>;
  }[];
  timestamp: Record<string, unknown>;
}

// 参数接口
export interface SelectResourcesParams {
  examId: number;
  resourceIds: number[];
}

// 返回数据接口
export interface SelectResourcesRes {
  code: number;
  message: string;
  data: string;
  timestamp: Record<string, unknown>;
}

const token = localStorage.getItem("token");

// 获取所有资源列表
const getResourcesListAPI = async (): Promise<GetResourcesListRes> => {
  const token = localStorage.getItem("token");
  return request("/api/exam-resources/list", {
    method: "get",
    headers: {
      "Authorization": `Bearer ${token}`,
    },
  });
};

// 选择资源并关联到考试
const selectResourcesAPI = async (params: SelectResourcesParams): Promise<SelectResourcesRes> => {
  const token = localStorage.getItem("token");
  return request("/api/exam-resources/select-resources", {
    method: "post",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${token}`,
    },
    data: JSON.stringify(params),
  });
};

export { getResourcesListAPI, selectResourcesAPI };